"======================================================================
"
" plugins.vim - 插件配置
"
"======================================================================
" vim: set ts=4 sw=4 tw=78 noet fdm=marker foldlevel=1

" 配置主目录
let s:home = fnamemodify(resolve(expand('<sfile>:p')), ':h:h')

" 默认启用的组件
let g:plugin_components = [
	\ "lightline",
	\ "colorschemes",
	\ "commentary",
	\ "common",
	\ "fern",
	\ "git",
	\ "go",
	\ "leaderf",
	\ "rainbow",
	\ ]

" 如果存在自定义插件组件配置则采用自定义的
" 可以在 init/plugins.local.vim 中对 g:plugin_components 进行修改
" 如：
" let g:plugin_components[0] = 'airline'
" let g:plugin_components = g:plugin_components + ['vimcdoc', 'hexokinase', 'ale', 'local', 'markdown', 'coc', 'neosnippet']
if filereadable(s:home.'/init/plugins.local.vim')
	LoadScript init/plugins.local.vim
endif

for component in g:plugin_components
	let file = s:home.'/components/'.component.'.preset.vim'
	if filereadable(file)
		exec 'source '.file
	endif
endfor

call plug#begin(s:home.'/plugins')

for component in g:plugin_components
	let file = s:home.'/components/'.component.'.plugins.vim'
	if filereadable(file)
		exec 'source '.file
	endif
endfor

call plug#end()

for component in g:plugin_components
	let file = s:home.'/components/'.component.'.config.vim'
	if filereadable(file)
		exec 'source '.file
	endif
	let localfile = s:home.'/components/'.component.'.config.local.vim'
	if filereadable(localfile)
		exec 'source '.localfile
	endif
endfor
